package com.zhuangyuan.cloud.data.entities;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.id.GUIDGenerator;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@Entity
@Table(name = "h_category")
public class Category extends BaseEntity{

    public Category(){}
    public Category(String name,int level,String shortcut,String parentId){
        this.id = UUID.randomUUID().toString();
        this.name = name;
        this.level = level;
        this.shortcut = shortcut;
        this.parentId = parentId;
    }

    @Id
    @GenericGenerator(name = "my-guid",strategy = "com.zhuangyuan.cloud.data.entities.GUIDGenerator")
    @GeneratedValue(generator = "my-guid")
    protected String id;
    @Column
    private String name;
    @Column
    private int level;
    @Column
    private String shortcut;
    @Column
    private int status;
    @Column(name = "parent_id")
    private String parentId;

    @Transient
    private List<Category> children = new ArrayList<>();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public String getShortcut() {
        return shortcut;
    }

    public void setShortcut(String shortcut) {
        this.shortcut = shortcut;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public List<Category> getChildren(){
        return children;
    }
    public void addChild(Category child){
        this.children.add(child);
    }
}
